/*************************************************************************
> File Name: io.cpp
> Author: hzy
> Created Time: 2023-08-17 22:02:18
> Description:
************************************************************************/
#include "../Headers/io.h"
#include <iostream>
using namespace std;

int IO::getFlag()
{
    bool loop = false;
    do
    {
        try
        {
            flagInput();
            loop = false;
        }
        catch (const logic_error &e)
        {
            loop = true;
            cout << e.what() << endl;
            cout << " --- " << endl;
        }
    } while (loop);
    return flag;
}
void IO::showMenu()
{
    cout << "****************************************" << endl;
    cout << "**********欢迎使用职工管理系统**********" << endl;
    cout << "***********  1.增加职工信息  ***********" << endl;
    cout << "***********  2.显示职工信息  ***********" << endl;
    cout << "***********  3.删除离职职工  ***********" << endl;
    cout << "***********  4.修改职工信息  ***********" << endl;
    cout << "***********  5.查找职工信息  ***********" << endl;
    cout << "***********  6.按照编号排序  ***********" << endl;
    cout << "***********  7.清空所有文档  ***********" << endl;
    cout << "***********  0.退出管理程序  ***********" << endl;
    cout << "****************************************" << endl;
}
void IO::flagInput()
{
    cout << "请输入操作符" << endl;
    int temp = 0;
    scanf("%*[^0-9]");
    scanf("%d%*[^\n]", &temp);
    if (temp < 0 || temp > 7)
    {
        throw logic_error("操作符错误");
    }
    flag = temp;
}
void IO::clear()
{
    system("cls");
}
Person IO::inputPerson()
{
    string name;
    int postId;
    cout << "请输入姓名" << endl;
    cin >> name;
    cout << "请输入职称序号" << endl;
    cout << "1.老板 2.经理 3.员工";
    while (true)
    {
        scanf("%*[^0-9]");
        scanf("%d%*[^\n]", &postId);
        if (postId > 0 && postId < 4)
        {
            break;
        }
        cout << "请重新输入" << endl;
    }
    Person p(name, postId);
    return p;
}
void IO::showResult(string result)
{
    cout << "运行结果： " << result << endl;
    cout << endl;
}
